package com.siwei.mes.entity.experiment;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.config.UidUtils;
import com.siwei.mes.enums.ExperimentStatusEnum;
import com.siwei.mes.enums.GenerateCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;


/**
 * 试验台账(Experiment)实体类
 *
 * @author linzi
 * @since 2023-12-18 22:11:46
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_experiment")
@ApiModel(value = "Experiment", description = "试验台账")
public class Experiment implements Serializable {
    private static final long serialVersionUID = 199063996171873048L;
    @Id
    @ApiModelProperty(value = "试验台账主键ID", name = "id")
    private Long id;
    /**
     * 试验编号
     */
    @Column(name = "experiment_no")
    @ApiModelProperty(value = "试验编号", name = "experimentNo")
    private String experimentNo;

    @Column(name = "check_type")
    @ApiModelProperty(value = "检查类型 1-快检 2-批检")
    private Integer checkType;

    @ApiModelProperty(value = "配合比")
    @NotBlank(groups = {AddGroup.class}, message = "配合比编码为空！")
    private String phb;

    @Column(name = "ksdj")
    @ApiModelProperty(value = "抗渗等级")
    private String ksdj;

    @Column(name = "conversion_factor")
    @ApiModelProperty(value = "抗折要求")
    private String conversionFactor;

    /**
     * 报告编号
     */
    @Column(name = "report_no")
    @ApiModelProperty(value = "报告编号", name = "reportNo")
    private String reportNo;
    /**
     * 试验状态    0-待接收  1-待取样  2-试验中 3-已完成 4-已拒绝  5-已作废
     */
    @Column(name = "experiment_status")
    @ApiModelProperty(value = "试验状态  0-待接收  1-待取样  2-试验中 3-已完成 4-已拒绝  5-已作废", name = "experimentStatus")
    private Integer experimentStatus;
    /**
     * 1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土
     */
    @Column(name = "experiment_type")
    @ApiModelProperty(value = "1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土", name = "experimentType")
    private Integer experimentType;
    /**
     * 委托原因 字典code  （entrust_reason）
     */
    @Column(name = "entrust_reason_code")
    @ApiModelProperty(value = "委托原因 字典code  （entrust_reason）", name = "entrustReasonCode")
    private String entrustReasonCode;
    /**
     * 委托原因 字典名称
     */
    @Column(name = "entrust_reason_name")
    @ApiModelProperty(value = "委托原因 字典名称", name = "entrustReasonName")
    private String entrustReasonName;
    /**
     * 委托人id
     */
    @Column(name = "entrust_person_id")
    @ApiModelProperty(value = "委托人id", name = "entrustPersonId")
    private Long entrustPersonId;
    /**
     * 委托人名称
     */
    @Column(name = "entrust_person_name")
    @ApiModelProperty(value = "委托人名称", name = "entrustPersonName")
    private String entrustPersonName;
    /**
     * 委托时间
     */
    @Column(name = "entrust_time")
    @ApiModelProperty(value = "委托时间", name = "entrustTime")
    private Date entrustTime;
    /**
     * 委托试验
     */
    @Column(name = "entrust_experiment")
    @ApiModelProperty(value = "委托试验", name = "entrustExperiment")
    private String entrustExperiment;
    /**
     * 样品等级
     */
    @Column(name = "sample_level")
    @ApiModelProperty(value = "样品等级", name = "sampleLevel")
    private String sampleLevel;

    @Column(name = "material_abbreviation")
    @ApiModelProperty(value = "材料简称")
    private String materialAbbreviation;

    @Column(name = "materials_name")
    @ApiModelProperty(value = "材料名称")
    private String materialsName;

    @Column(name = "materials_specs")
    @ApiModelProperty(value = "材料规格")
    private String materialsSpecs;


    @Column(name = "matter_abbreviation")
    @ApiModelProperty(value = "物料简称")
    private String matterAbbreviation;

    @Column(name = "matter_name")
    @ApiModelProperty(value = "物料名称")
    private String matterName;

    @Column(name = "matter_specs")
    @ApiModelProperty(value = "物料规格")
    private String matterSpecs;


    /**
     * 代表数量
     */
    @Column(name = "behalf_number")
    @ApiModelProperty(value = "代表数量", name = "behalfNumber")
    private Double behalfNumber;
    /**
     * 试验依据
     */
    @Column(name = "experiment_gist")
    @ApiModelProperty(value = "试验依据", name = "experimentGist")
    private String experimentGist;
    /**
     * 判断依据
     */
    @Column(name = "judge_gist")
    @ApiModelProperty(value = "判断依据", name = "judgeGist")
    private String judgeGist;
    /**
     * 主要仪器设备
     */
    @Column(name = "equipment")
    @ApiModelProperty(value = "主要仪器设备编号 之前是仪器设备名称 改为仪器设备编号", name = "equipment")
    private String equipment;
    /**
     * 温度
     */
    @Column(name = "temperature")
    @ApiModelProperty(value = "温度", name = "temperature")
    private String temperature;
    /**
     * 湿度
     */
    @Column(name = "humidness")
    @ApiModelProperty(value = "湿度", name = "humidness")
    private String humidness;
    /**
     * 试验人id
     */
    @Column(name = "experiment_person_id")
    @ApiModelProperty(value = "试验人id", name = "experimentPersonId")
    private Long experimentPersonId;
    /**
     * 试验人名称
     */
    @Column(name = "experiment_person_name")
    @ApiModelProperty(value = "试验人名称", name = "experimentPersonName")
    private String experimentPersonName;
    /**
     * 试验时间
     */
    @Column(name = "experiment_time")
    @ApiModelProperty(value = "试验时间", name = "experimentTime")
    private Date experimentTime;
    /**
     * 校核人id
     */
    @Column(name = "check_person_id")
    @ApiModelProperty(value = "校核人id", name = "checkPersonId")
    private Long checkPersonId;
    /**
     * 校核人名称
     */
    @Column(name = "check_person_name")
    @ApiModelProperty(value = "校核人名称", name = "checkPersonName")
    private String checkPersonName;
    /**
     * 校核时间
     */
    @Column(name = "check_time")
    @ApiModelProperty(value = "校核时间", name = "checkTime")
    private Date checkTime;
    /**
     * 批准人id
     */
    @Column(name = "approve_person_id")
    @ApiModelProperty(value = "批准人id", name = "approvePersonId")
    private Long approvePersonId;
    /**
     * 批准人名称
     */
    @Column(name = "approve_person_name")
    @ApiModelProperty(value = "批准人名称", name = "approvePersonName")
    private String approvePersonName;
    /**
     * 批准时间
     */
    @Column(name = "approve_time")
    @ApiModelProperty(value = "批准时间", name = "approveTime")
    private Date approveTime;
    /**
     * 是否合格 1-合格 2-不合格
     */
    @Column(name = "is_qualified")
    @ApiModelProperty(value = "是否合格 1-合格 2-不合格", name = "isQualified")
    private Integer isQualified;
    /**
     * 结论
     */
    @Column(name = "conclusion")
    @ApiModelProperty(value = "结论", name = "conclusion")
    private String conclusion;
    /**
     * 备注
     */
    @Column(name = "remark")
    @ApiModelProperty(value = "备注", name = "remark")
    private String remark;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    /**
     * 接收人id
     */
    @Column(name = "accept_person_id")
    @ApiModelProperty(value = "接收人id", name = "acceptPersonId")
    private Long acceptPersonId;
    /**
     * 接收人名称
     */
    @Column(name = "accept_person_name")
    @ApiModelProperty(value = "接收人名称", name = "acceptPersonName")
    private String acceptPersonName;
    /**
     * 接收时间
     */
    @Column(name = "accept_time")
    @ApiModelProperty(value = "接收时间", name = "acceptTime")
    private Date acceptTime;
    /**
     * 取样人id
     */
    @Column(name = "sampling_person_id")
    @ApiModelProperty(value = "取样人id", name = "samplingPersonId")
    private Long samplingPersonId;
    /**
     * 取样人名称
     */
    @Column(name = "sampling_person_name")
    @ApiModelProperty(value = "取样人名称", name = "samplingPersonName")
    private String samplingPersonName;
    /**
     * 取样时间
     */
    @Column(name = "sampling_time")
    @ApiModelProperty(value = "取样时间", name = "samplingTime")
    private Date samplingTime;
    /**
     * 完成人id
     */
    @Column(name = "finish_person_id")
    private Long finishPersonId;
    /**
     * 完成人名称
     */
    @Column(name = "finish_person_name")
    @ApiModelProperty(value = "完成人名称", name = "finishPersonName")
    private String finishPersonName;
    /**
     * 完成时间
     */
    @Column(name = "finish_time")
    @ApiModelProperty(value = "完成时间", name = "finishTime")
    private Date finishTime;
    /**
     * 拒绝人id
     */
    @Column(name = "refuse_person_id")
    @ApiModelProperty(value = "拒绝人id", name = "refusePersonId")
    private Long refusePersonId;
    /**
     * 拒绝人名称
     */
    @Column(name = "refuse_person_name")
    @ApiModelProperty(value = "拒绝人名称", name = "refusePersonName")
    private String refusePersonName;
    /**
     * 拒绝时间
     */
    @Column(name = "refuse_time")
    @ApiModelProperty(value = "拒绝时间", name = "refuseTime")
    private Date refuseTime;
    /**
     * 规格id pk_materials_spec_config 表的id
     */
    @Column(name = "spec_id")
    @ApiModelProperty(value = "规格id  pk_materials_spec_config 表的id")
    @NotNull(groups = {AddGroup.class}, message = "材料名称规格为空")
    private Long specId;

    @Column(name = "molding_time")
    @ApiModelProperty(value = "成型时间")
    private Date moldingTime;

    @Column(name = "curing_mode")
    @ApiModelProperty(value = "养护条件")
    private String curingMode;

    @Column(name = "entrust_state")
    @ApiModelProperty(value = "委托任务状态 等待检测 0  已检测 1")
    private String entrustState;

    @Column(name = "batch")
    @ApiModelProperty(value = "批次")
    private String batch;

    @Column(name = "batch_number")
    @ApiModelProperty(value = "批号")
    private String batchNumber;

    @Column(name = "factory")
    @ApiModelProperty(value = "生产厂家")
    private String factory;

    @Column(name = "factory_called")
    @ApiModelProperty(value = "生产厂家简称")
    private String factoryCalled;

    @Column(name = "supply_company_name")
    @ApiModelProperty(value = "供应商名称")
    private String supplyCompanyName;

    @Column(name = "supply_company_called")
    @ApiModelProperty(value = "供应商简称")
    private String supplyCompanyCalled;

    @Column(name = "experiment_company")
    @ApiModelProperty(value = "委托单位")
    private String experimentCompany;

    @Column(name = "experiment_dept")
    @ApiModelProperty(value = "委托部门")
    private String experimentDept;

    @Column(name = "phone")
    @ApiModelProperty(value = "联系电话")
    private String phone;

    @Column(name = "handling_suggestion")
    @ApiModelProperty(value = "处理意见")
    private String handlingSuggestion;

    @Column(name = "materials_id")
    @ApiModelProperty(value = "pk_materials表主键ID")
    private String materialsId;

    @Column(name = "create_check_type")
    @ApiModelProperty(value = "生成检测类型  对应定时任务生成  默认  0-常规  10-月检  20-季检  30-半年检  40-年检")
    private Integer createCheckType;

    @Column(name = "create_type")
    @ApiModelProperty(value = "生成类型  1.自动生成  2.新建委托  3.定时任务")
    private Integer createType;

    @Column(name = "is_save_or_finish")
    @ApiModelProperty(value = "是否保存或完成  1-是  0-不是")
    private Integer isSaveOrFinish;

    @Column(name = "is_xnbg")
    @ApiModelProperty(value = "是否是性能报告  1-是  0-不是")
    private Integer isXnbg;

    @Column(name = "report_date")
    @ApiModelProperty(value = "协会报告日期")
    private Date reportDate;

    @Column(name = "admission_time")
    @ApiModelProperty(value = "入场时间")
    private Date admissionTime;

    @Column(name = "certificate_no")
    @ApiModelProperty(value = "备案证号")
    private String certificateNo;

    @Column(name = "self_supply")
    @ApiModelProperty(value = "甲供 1-是 0-否", name = "selfSupply")
    private Integer selfSupply;

    @Column(name = "is_new_task")
    @ApiModelProperty(value = "是否有新任务单 1-有 0-没有")
    private Integer isNewTask;

    @Transient
    @ApiModelProperty(value = "任务单号")
    private String FRwdh;

    @Transient
    @ApiModelProperty(value = "工程名称")
    private String projectName;

    @Transient
    @ApiModelProperty(value = "客户名称")
    private String customerName;

    @Transient
    @ApiModelProperty(value = "多个状态集合")
    private List<Integer> experimentStatusList;

    @Transient
    @ApiModelProperty(value = "多个试验类型")
    private List<Integer> experimentTypeList;

    @Transient
    @ApiModelProperty(value = "多个委托原因code")
    private List<String> entrustReasonCodeList;

    @Transient
    @ApiModelProperty(value = "关键字搜索")
    private String keyword;

    @Transient
    @ApiModelProperty(value = "开始时间")
    private String startTime;

    @Transient
    @ApiModelProperty(value = "结束时间")
    private String endTime;


    @Transient
    @ApiModelProperty(value = "委托日期开始时间")
    private String beginTime;

    @Transient
    @ApiModelProperty(value = "委托日期结束时间")
    private String comTime;

    @Transient
    @ApiModelProperty(value = "委托任务状态不为等待检测")
    private String entrustStateNot;

    @Transient
    @ApiModelProperty(value = "是否查询的已完成的 0-未完成  1-已完成 2-根据协会委托编号排序")
    private Integer isFinish;

    @Transient
    @ApiModelProperty(value = "实时统计出来的代表数量(混凝土)")
    private Double realBehalfNumber;

    @Transient
    @ApiModelProperty(value = "实时统计出来的代表数量(原材料)")
    private Double realMaterialNumber;

    @Transient
    @ApiModelProperty(value = "查询类型 1 选择样品")
    private String queryType;

    @Transient
    @ApiModelProperty(value = "协会用户名")
    private String societyUserName;

    @Transient
    @ApiModelProperty(value = "指标配置数组")
    private Set<String> testProjectCodeList;

    @Transient
    @ApiModelProperty(value = "多个试验委托id集合")
    private List<Long> experimentIdList;

    @Transient
    @ApiModelProperty(value = "是否协会查询（1是）", name = "isAssociation")
    private String isAssociation;

    @Transient
    @ApiModelProperty(value = "协会报告编号", name = "reportId")
    private String reportId;

    /**
     * 进场id
     */
    @Transient
    @ApiModelProperty(value = "进场id", name = "importId")
    private String importId;


    /**
     * 批号用/等同于样品id
     */
    @Transient
    @ApiModelProperty(value = "批号用/等同于样品id", name = "sampleNo")
    private String sampleNo;
    /**
     * 台账id
     */
    @Transient
    @ApiModelProperty(value = "台账id", name = "consignId")
    private String consignId;
    /**
     * 取样id
     */
    @Transient
    @ApiModelProperty(value = "取样id", name = "sampleId")
    private String sampleId;

    /**
     * 完成状态（0未完成1已完成）
     */
    @Transient
    @ApiModelProperty(value = "完成状态（0未完成1已完成）", name = "finistStatus")
    private String finistStatus;
    /**
     * 失败原因
     */
    @Transient
    @ApiModelProperty(value = "上传失败原因", name = "reason")
    private String reason;

    @Transient
    @ApiModelProperty(value = "下载失败原因", name = "downloadReason")
    private String downloadReason;

    @Transient
    @ApiModelProperty(value = "所有试验项目  用逗号分隔")
    private String testProjectNameStr;

    @Transient
    @ApiModelProperty(value = "试验项目code")
    private String testProjectCode;

    @Transient
    @ApiModelProperty(value = "试验项目名称模糊匹配")
    private String entrustExperimentBlur;

    @Transient
    @ApiModelProperty(value = "委托编号模糊匹配 实验委托编号以及协会委托编号")
    private String noKeyword;

    @Transient
    @ApiModelProperty(value = "检测日期 所做实验项目检测日期的最小值拼接最大值")
    private String jcrq;

    @Transient
    @ApiModelProperty(value = "pei")
    private String lq;

    @Transient
    @ApiModelProperty(value = "工程名称 多个用逗号分隔")
    private String projectNameStr;

    public Experiment init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date()).setExperimentStatus(ExperimentStatusEnum.WAIT_ACCEPT.getCode())
                    .setIsDel(0).setExperimentNo(UidUtils.genNo(GenerateCodeEnum.EXPERIMENT.getCode()));
        }
        return this;
    }

    public Experiment erpInit(boolean isCreate) {
        this.setUpdateTime(new Date());
        if (isCreate) {
            this.setCreateTime(new Date()).setExperimentStatus(ExperimentStatusEnum.WAIT_ACCEPT.getCode())
                    .setIsDel(0).setExperimentNo(UidUtils.genNo(GenerateCodeEnum.EXPERIMENT.getCode()));
        }
        return this;
    }

    public Experiment phbInit(boolean isCreate) {
        this.setUpdateTime(new Date());
        if (isCreate) {
            this.setCreateTime(new Date()).setExperimentStatus(ExperimentStatusEnum.WAIT_ACCEPT.getCode())
                    .setIsDel(0).setExperimentNo(UidUtils.genNo(GenerateCodeEnum.EXPERIMENT.getCode()));
        }
        return this;
    }

    public Experiment tcInit(boolean isCreate) {
        this.setUpdateTime(new Date());
        if (isCreate) {
            this.setCreateTime(new Date()).setExperimentStatus(ExperimentStatusEnum.WAIT_ACCEPT.getCode())
                    .setIsDel(0).setExperimentNo(UidUtils.genNo(GenerateCodeEnum.EXPERIMENT.getCode()));
        }
        return this;
    }

    public Experiment laboratoryInit(boolean isCreate) {
        this.setUpdateTime(new Date());
        if (isCreate) {
            this.setCreateTime(new Date()).setExperimentStatus(ExperimentStatusEnum.WAIT_ACCEPT.getCode())
                    .setIsDel(0).setExperimentNo(UidUtils.genNo(GenerateCodeEnum.EXPERIMENT.getCode()));
        }
        return this;
    }
}
